using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Reflection;

namespace IGGCore
{
    /// <summary>
    /// The parser of historic facts.
    /// It retrieves single history tidbit for the applications
    /// </summary>
    public class HistoryParser : BaseParser
    {
        private string m_historyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) 
            + CoreConstants.FILE_PATH_HISTORY;

        private XmlNodeList storyList;
        private Random rnd;

        public void LoadHistory()
        {
            rnd = new Random();
            XmlDocument historyDoc = new XmlDocument();
            historyDoc.Load(m_historyPath);
            storyList = historyDoc.GetElementsByTagName("story");
        }

        /// <summary>
        /// Update the history tidbit in the current scoreboard
        /// </summary>
        public string GetHistoryTidbit()
        {
            return storyList[rnd.Next(storyList.Count)].InnerText.Trim();
        }
    }
}
